/*
 * @Author: jiutian
 * @Date: 2023-01-31 11:47:08
 * @LastEditTime: 2023-03-10 17:05:09
 * @LastEditors:  
 */
const express = require("express");
const router = express.Router();
const handler = require("../router_handler/check");
const { validate, Joi } = require("express-validation");
const { commonUploadPic } = require("../config/file");

router.post(
  "/saveBlog",
  validate({
    body: Joi.object({
      blogStr: Joi.string().required(),
      blogText: Joi.string().required(),
      blogTitle: Joi.string().required(),
    }),
  }),
  handler.saveBlog
);

router.post(
  "/uploadBlogImg",
  commonUploadPic("images").single("blogImg"),
  (req, res) => {
    res.send({
      code: 200,
      msg: "上次成功",
      data: {
        url: `/blogServe/images/${req.file.resetName}`,
        alt: req.file.resetName,
      },
    });
  }
);

router.post(
  "/uploadBlogVideo",
  commonUploadPic("videos").single("blogVideo"),
  (req, res) => {
    res.send({
      code: 200,
      msg: "上次成功",
      data: {
        url: `/blogServe/videos/${req.file.resetName}`,
        alt: req.file.resetName,
      },
    });
  }
);

router.get(
  "/getBlogList",
  validate({
    query: Joi.object({
      keyword: Joi.string().allow(null).allow(""),
      pageSize: Joi.number().allow(null),
      pageNum: Joi.number().allow(null),
    }),
  }),
  handler.getBlogList
);

router.get(
  "/getBlogById",
  validate({
    query: Joi.object({
      id: Joi.number().required(),
    }),
  }),
  handler.getBlogById
);

router.get("/getCurrentUser", handler.getCurrentUser);

router.post(
  "/operateLike",
  validate({
    body: Joi.object({
      type: Joi.string().required(),
      id: Joi.number().required(),
    }),
  }),
  handler.operateLike
);

router.get(
  "/checkOperate",
  validate({
    query: Joi.object({
      id: Joi.number().required(),
    }),
  }),
  handler.checkOperate
);

router.post(
  "/operateCollect",
  validate({
    body: Joi.object({
      type: Joi.string().required(),
      id: Joi.number().required(),
    }),
  }),
  handler.operateCollect
);

router.post(
  "/publishCommit",
  validate({
    body: Joi.object({
      context: Joi.string().required().max(500),
      id: Joi.number().required(),
    }),
  }),
  handler.publishCommit
);

router.get(
  "/getCommitList",
  validate({
    query: Joi.object({
      id: Joi.string().required(),
      pageSize: Joi.number().allow(null),
      pageNum: Joi.number().allow(null),
    }),
  }),
  handler.getCommitList
);

router.get(
  "/getBlogerList",
  validate({
    query: Joi.object({
      keyword: Joi.string().allow(null).allow(""),
    }),
  }),
  handler.getBlogerList
);

router.get(
  "/getMessageList",
  validate({
    query: Joi.object({
      replyerId: Joi.number().required(),
      senderId: Joi.number().required(),
      pageSize: Joi.number().allow(null),
      pageNum: Joi.number().allow(null),
    }),
  }),
  handler.getMessageList
);

router.post(
  "/operateFocus",
  validate({
    body: Joi.object({
      type: Joi.string().required(),
      id: Joi.number().required(),
    }),
  }),
  handler.operateFocus
);

router.get(
  "/getUnReadCount",
  validate({
    query: Joi.object({
      senderId: Joi.number().required(),
    }),
  }),
  handler.getUnReadCount
);

router.get(
  "/getPersonInfo",
  validate({
    query: Joi.object({
      id: Joi.number().required(),
    }),
  }),
  handler.getPersonInfo
);

router.get(
  "/getBlogListByUserId",
  validate({
    query: Joi.object({
      id: Joi.number().required(),
      pageNum: Joi.number().required(),
      pageSize: Joi.number().required(),
    }),
  }),
  handler.getBlogListByUserId
);

router.post(
  "/deleteRowByid",
  validate({
    body: Joi.object({
      id: Joi.number().required(),
    }),
  }),
  handler.deleteRowByid
);

router.get(
  "/getLikeList",
  validate({
    query: Joi.object({
      id: Joi.number().required(),
      pageNum: Joi.number().required(),
      pageSize: Joi.number().required(),
    }),
  }),
  handler.getLikeList
);

router.get(
  "/getCollectList",
  validate({
    query: Joi.object({
      id: Joi.number().required(),
      pageNum: Joi.number().required(),
      pageSize: Joi.number().required(),
    }),
  }),
  handler.getCollectList
);

router.get(
  "/getFocusList",
  validate({
    query: Joi.object({
      id: Joi.number().required(),
      pageNum: Joi.number().required(),
      pageSize: Joi.number().required(),
    }),
  }),
  handler.getFocusList
);

router.get(
  "/getCommitListPerson",
  validate({
    query: Joi.object({
      id: Joi.number().required(),
      pageNum: Joi.number().required(),
      pageSize: Joi.number().required(),
    }),
  }),
  handler.getCommitListPerson
);

router.post(
  "/deleteCommitById",
  validate({
    body: Joi.object({
      id: Joi.number().required(),
    }),
  }),
  handler.deleteCommitById
);

router.get(
  "/globalSearch",
  validate({
    query: Joi.object({
      keyword: Joi.string(),
    }),
  }),
  handler.globalSearch
);

module.exports = router;
